package com.ruoyi.project.hcy.product.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hcy.product.domain.img.ProImg;
import com.ruoyi.project.hcy.product.domain.product.Product;
import com.ruoyi.project.hcy.product.domain.product.ProductNameVo;
import com.ruoyi.project.hcy.product.domain.product.ProductVo;
import com.ruoyi.project.hcy.product.service.IProImgService;
import com.ruoyi.project.hcy.product.service.IProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ProFavoritesController
 * @Author SAI
 * @Date 2020/9/20 14:34
 * @Description ProFavoritesController
 * @Version 1.0
 */
@Controller
@RequestMapping("/hcy/product/proFavorites")
public class ProFavoritesController extends BaseController {

    @Autowired
    private IProductService productService;

    @Autowired
    private IProImgService proImgService;

    private String prefix = "hcy/product/favorites";

    @RequiresPermissions("product:proFavorites:view")
    @GetMapping()
    public String operlog(){
        return prefix+"/proFavorites";
    }

    @RequiresPermissions("product:proFavorites:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Product product){
        startPage();
        List<ProductVo> list = productService.selectFavoritesProductList(product);
        return getDataTable(list);
    }

    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId")Long productId, ModelMap mmap){
        ProductNameVo product = productService.selectProductNameById(productId);
        mmap.put("product",product);
//        ProImg proImg = proImgService.selectImgById(product.getImgId());
//        mmap.put("imgUrl",proImg.getImgUrl());
        return prefix+"/check";
    }

}
